<?php
/**
 * 监控服务  ws  http 81 82端口
 * Created by PhpStorm.
 * User: DRG
 * Date: 2018/6/21
 * Time: 20:57
 */
// netstat -anp 2>/dev/null | grep 81 |grep listen | wc -l
class Server {

    const PORT = 81;

    public function port()
    {
        $shell  =  "netstat -anp 2>/dev/null | grep ". self::PORT . " | grep LISTEN | wc -l";

        $result = shell_exec($shell);
        if($result != 1) {
            // 发送报警服务 邮件 短信
            ///todo
            echo date("Ymd H:i:s")."error".PHP_EOL;
        } else {
            echo date("Ymd H:i:s")."succss".PHP_EOL;
        }
    }
}
// nohup 命令了解一下  程序后台执行
swoole_timer_tick(2000, function($timer_id) {
    (new Server())->port();
    echo "time-start".PHP_EOL;
});